import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../dd_core/dd_config.dart';
import '../../../dd_core/dd_log_service.dart';
import '../../../dd_core/dd_other.dart';
import '../../../dd_models/dd_hive_works_model.dart';
import '../../dd_home/controllers/dd_comment_controller.dart';
import '../../dd_home/pages/dd_comment_page.dart';
import '../../dd_personal_center/views/dd_view_background.dart';
import '../controllers/dd_video_controller.dart';
import '../views/dd_video_background.dart';
import '../views/dd_video_card.dart';
import 'dd_video_player.dart';

class DDVideoPage extends StatefulWidget {
  const DDVideoPage({Key? key}) : super(key: key);

  @override
  State<DDVideoPage> createState() => _DDVideoPageState();
}

class _DDVideoPageState extends State<DDVideoPage> {
  DDVideoController _controller = DDVideoController();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DDVideoController>(
        init: _controller,
        initState: (state) {
          DDLogService().ddGa(page: "video_page");
        },
        dispose: (state) {},
        builder: (controller) {
          return Scaffold(
            backgroundColor: Color(0xFFE7F6FC),
            body: SafeArea(
                top: false,
                child: Stack(
                  children: [
                    Positioned.fill(
                    child:
                    DDVideoBackgroud(),),
                    Positioned(
                      child: Padding(
                        padding: const EdgeInsets.only(
                            top: 50.0, bottom: 0, right: 14, left: 14),
                        child: Obx(
                          () => ListView.builder(
                              itemBuilder: (context, index) {
                                return DDVideoCard(
                                  model: controller.list[index],
                                  onMore: () {
                                    _showBottomSheet(
                                        context, controller.list[index]);
                                  },
                                  onComment: () {
                                    showModalBottomSheet(
                                      context: context,
                                      isScrollControlled: true,
                                      builder: (context) => Container(
                                        child: DDCommentPage(
                                          model: controller.list[index],
                                          commentController:
                                              Get.put(DDCommentController()),
                                        ),
                                      ),
                                    );
                                  },
                                  onLike: () {
                                    controller
                                        .updateMyLike(controller.list[index]);
                                  },
                                  onCollection: () {
                                    controller
                                        .updateFollow(controller.list[index]);
                                  },
                                  onClick: () {
                                    DDRoutesConfig.push(DDVideoScreen(model: controller.list[index],),routeName:"/videoPlayer");
                                  },
                                );
                              },
                              itemCount: controller.list.length),
                        ),
                      ),
                    ),
                  ],
                )),
          );
        });
  }

  void _showBottomSheet(BuildContext context, HiveWorksModel model) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16.0)),
      ),
      builder: (BuildContext context) {
        return SafeArea(
            child: Container(
          padding: EdgeInsets.all(16.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              ListTile(
                title: Center(
                    child: Text(model.myFollow ?? false ? 'Unfollow' : 'Follow', style: TextStyle(fontSize: 16))),
                onTap: () {
                  // Add your follow action here
                  Navigator.pop(context);
                  _controller.updateFollow(model);
                },
              ),
              ListTile(
                title: Center(
                    child: Text('Block', style: TextStyle(fontSize: 16))),
                onTap: () {
                  // Add your block action here
                  Navigator.pop(context);
                  _controller.updateMyBlock(model);
                },
              ),
              ListTile(
                title: Center(
                    child: Text('Report', style: TextStyle(fontSize: 16))),
                onTap: () {
                  // Add your report action here
                  Navigator.pop(context);
                  _showBottomSheet1(context, model);
                },
              ),
              SizedBox(height: 16),
              DDViewBackGround(
                content: Container(
                  width: 183,
                  height: 44,
                  child: DDSafeButton(
                    child: Text(
                      "Cancel",
                      style: TextStyle(fontSize: 16, color: Color(0xff53BFD7)),
                    ),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                  ),
                ),
              ),
            ],
          ),
        ));
      },
    );
  }

  void _showBottomSheet1(BuildContext context, HiveWorksModel model) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16.0)),
      ),
      builder: (BuildContext context) {
        return SafeArea(
            child: Container(
              padding: EdgeInsets.all(16.0),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  ListTile(
                    title: Center(
                        child:
                        Text('Pornographic', style: TextStyle(fontSize: 16))),
                    onTap: () {
                      Navigator.pop(context);
                      _controller.report(model,'Pornographic');
                    },
                  ),
                  ListTile(
                    title: Center(
                        child:
                        Text('False gender', style: TextStyle(fontSize: 16))),
                    onTap: () {
                      // Add your block action here
                      Navigator.pop(context);
                      _controller.report(model,'False gender');
                    },
                  ),
                  ListTile(
                    title: Center(
                        child: Text('Fraud', style: TextStyle(fontSize: 16))),
                    onTap: () {
                      // Add your report action here
                      Navigator.pop(context);
                      _controller.report(model,'Fraud');
                    },
                  ),
                  ListTile(
                    title: Center(
                        child: Text('Political sensitive',
                            style: TextStyle(fontSize: 16))),
                    onTap: () {
                      // Add your report action here
                      Navigator.pop(context);
                      _controller.report(model,'Political sensitive');
                    },
                  ),
                  ListTile(
                    title: Center(
                        child: Text('Other', style: TextStyle(fontSize: 16))),
                    onTap: () {
                      // Add your report action here
                      Navigator.pop(context);
                      _controller.report(model,'Other');
                    },
                  ),
                  SizedBox(height: 16),
                  DDViewBackGround(
                    content: Container(
                      width: 183,
                      height: 44,
                      child: DDSafeButton(
                        // padding: EdgeInsets.only(top: 20, bottom: 20),
                        child: Text(
                          "Cancel",
                          style: TextStyle(fontSize: 16, color: Color(0xff53BFD7)),
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      ),
                    ),
                  ),

                  // TextButton(
                  //   onPressed: () {
                  //     Navigator.pop(context);
                  //   },
                  //   child: Text('Cancel', style: TextStyle(fontSize: 18, color: Colors.blue)),
                  // ),
                ],
              ),
            ));
      },
    );
  }

  void _showSnackBar(String message, BuildContext context) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(message),
      ),
    );
  }
}
